import { Navigate, useLocation } from "react-router-dom";

export const AuthRoute = (props: any) => {
  const { children } = props;
  // 如果当前是login页面，直接返回
  const location = useLocation();

  if (location.pathname === "/login") {
    localStorage.removeItem("token");
    return <>{children}</>;
  }
  const token = localStorage.getItem("token");
  console.log("token", token);
  if (!token) {
    return <Navigate to="/login" />;
  }

  return <>{children}</>;
};
